import http from '@/utils/http'

const BASE_URL = '/system/resource'

export interface ResourceResp {
  id: string
  module: string
  code: string
  name: string
  sort: string
  description: string
  selected?: boolean
}

export interface ResourceDetailResp extends ResourceResp {

}

export interface ResourceGroupResp {
  module: string
  resourceList: ResourceResp[]
}

// 资源查询条件
export interface ResourceQuery {
  module?: string
  keyword?: string
}

/** @desc 查询资源列表 */
export function getList(query: ResourceQuery) {
  return http.get<ResourceResp[]>(`${BASE_URL}/list`, query)
}

/** @desc 查询资源组列表 */
export function getGroupList() {
  return http.get<ResourceResp[]>(`${BASE_URL}/list/group`)
}

/** @desc 查询资源详情 */
export function getDetail(id: string) {
  return http.get<ResourceDetailResp>(`${BASE_URL}/detail/${id}`)
}

/** @desc 创建资源 */
export function create(data: any) {
  return http.post(`${BASE_URL}/create`, data)
}

/** @desc 修改资源 */
export function update(data: any, id: string) {
  return http.post(`${BASE_URL}/update/${id}`, data)
}

/** @desc 删除资源 */
export function remove(id: string) {
  return http.post(`${BASE_URL}/delete/${id}`)
}

/** @desc 排序数据 */
export function sortResource(data: any) {
  return http.post(`${BASE_URL}/sort`, data)
}
